package com.mba.adapter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.mba.activity.ContentActivity;
import com.mba.activity.R;
import com.mba.activity.UserMainPageActivity;
import com.mba.base.MyOnClickLisenter;
import com.mba.bean.ContentInfo;
import com.mba.util.AsyncImageLoader;
import com.mba.widget.JListView;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MsgActivitiyAdapter extends BaseAdapter{
	
	private Context context;
	private ArrayList<ContentInfo> contentList;
	private AsyncImageLoader imageLoader;
	public MsgActivitiyAdapter(Context context, ArrayList<ContentInfo> contentList) {
		this.context=context;
		this.contentList = contentList;
		imageLoader=new AsyncImageLoader();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return contentList!=null?contentList.size():0;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, final ViewGroup arg2) {
		if(arg1==null){
			arg1=LayoutInflater.from(context).inflate(R.layout.msg_activity_adapter, null);
		}
		final ImageView avater = (ImageView) arg1.findViewById(R.id.msg_adapter_item_avatar);
		TextView name = (TextView) arg1.findViewById(R.id.msg_adapter_item_name);
		TextView area = (TextView) arg1.findViewById(R.id.msg_adapter_item_area);
		TextView content = (TextView) arg1.findViewById(R.id.msg_adapter_item_content);
		Button button = (Button) arg1.findViewById(R.id.msg_adapter_item_conten_get_detail_button);
		TextView reply = (TextView) arg1.findViewById(R.id.msg_brightly_replies_text);
		reply.setText("Test Information");
		
		final ContentInfo info = contentList.get(arg0);
		button.setTag(info.getId());
		//获取位置的监听事件
		area.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
			}
		});
		button.setOnClickListener(new MyOnClickLisenter(button.getTag(),arg0));
		/*
		button.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
					Intent intent = new Intent(arg0.getContext(),
						ContentActivity.class);
					Bundle bundle = new Bundle();
					bundle.putString("weiboId", weiboId);
					intent.putExtras(bundle);
					Activity act =(Activity) arg0.getContext();
					act.startActivity(intent);
			}
		});
		*/
		
		
		//异步加载图片
//		Drawable draw = imageLoader.loadDrawable(info.getUserIcon(), avater, new ImageCallback() {
//			
//			@Override
//			public void imageLoaded(Drawable drawable, ImageView iv, String url) {
//				avater.setImageDrawable(drawable);
//			}
//		});
		
//		avater.setImageDrawable(draw);
		avater.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(arg0.getContext(),UserMainPageActivity.class);
				Activity activity = (Activity) arg0.getContext();
				activity.startActivity(intent);
			}
		});
		
		name.setText(info.getUserName());
//		area.setText("");
		content.setText(info.getText());
		
		return arg1;
	}
	

}
